$(document).ready(function(){
	//global vars
	var code = $("#txt_code");
	var title = $("#txt_title");
	var content = $("#txt_content");
	var codeInfo = $("#codeInfo");
	var titleInfo = $("#titleInfo");
	var contentInfo = $("#contentInfo");
	
	//On blur
	code.blur(validateCode);
	title.blur(validateTitle);
	content.blur(validateContent);
	
	//On key press
	code.keyup(validateCode);
	title.keyup(validateTitle);
	content.keyup(validateContent);
	
	function validateCode(){
		//if it's NOT valid
		if(code.val().length < 4){
			code.removeClass("inp-form");
			code.addClass("inp-form-error");
			codeInfo.text("The Code must more than 3 letters !");
			codeInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			code.addClass("inp-form");
			code.removeClass("inp-form-error");
			codeInfo.text("");
			codeInfo.removeClass("error");
			return true;
		}
	}
	function validateTitle(){
		//if it's NOT valid
		if(title.val().length < 4){
			title.removeClass("inp-form");
			title.addClass("inp-form-error");
			titleInfo.text("The Title must more than 3 letters !");
			titleInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			title.addClass("inp-form");
			title.removeClass("inp-form-error");
			titleInfo.text("");
			titleInfo.removeClass("error");
			return true;
		}
	}
	function validateContent(){
		//if it's NOT valid
		if(content.val().length < 4){
			contentInfo.text("The Content is not null!");
			contentInfo.addClass("error");
			return false;
		}
		//if it's valid
		else{
			contentInfo.text("");
			contentInfo.removeClass("error");
			return true;
		}
	}
});